package com.demo.crm.springboot3security.entity;

import java.time.LocalDateTime;

import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.RelationManyToOne;
import com.mybatisflex.annotation.Table;

import lombok.Data;

/**
 * 表单表结构实体
 * 用于管理动态创建的数据表结构
 */
@Data
@Table("form_table_structures")
public class FormTableStructure {
    @Id(keyType = KeyType.Auto)
    private Long id;

    @Column("form_id")
    private Long formId;

    @RelationManyToOne(selfField = "formId", targetField = "id")
    private CustomForm form; // 源表单

    private String tableName;    // 物理表名

    private String createSql;    // 建表SQL

    private String indexSql;     // 索引SQL

    private String status;       // 表状态：CREATING, ACTIVE, UPDATING, INACTIVE

    private LocalDateTime createdAt;

    private LocalDateTime updatedAt;

    public void prePersist() {
        this.createdAt = LocalDateTime.now();
        this.updatedAt = LocalDateTime.now();
    }

    public void preUpdate() {
        this.updatedAt = LocalDateTime.now();
    }
} 